var deleteBtnID=""; //点击删除按钮ID
var myNumber=0;
function addProperty() {
    var newNumber=myNumber++;
    $toAdd='<div class="control-group" >\n' +
        '        <input class="control-label" placeholder="属性名" name="propertyName">\n' +
        '        <div class="controls">\n' +
        '        <input class="input-xlarge focused" type="text" placeholder="属性内容" name="propertyValue"><button id="btn'+newNumber+'" class="btn btn-primary myBtn" type="button" data-target="#delcfmModel" >删除</button>\n' +
        '        </div>\n' +
        '        </div>'
    deleteBtnID="btn"+newNumber; //给新增的删除按钮动态添加ID
    $("#addAttr").parent().before($toAdd); //将新增的属性输入框插入
    // $("form div:not(.form-actions) button .btn.btn-primary").click(function(event){   //每新增一个按钮都要重新查询删除按钮。
    //     $("#delcfmModel").modal("show");
    //     deleteBtnID=$(event.target).attr("id");
    // });
    $(".btn.btn-primary.myBtn").click(function(event){   //每新增一个按钮都要重新查询删除按钮。
        $("#delcfmModel").modal("show");
        deleteBtnID=$(event.target).attr("id");
    });

}


//通过按钮的ID删除属性
function deleteProperty() {
    $("#"+deleteBtnID).parent().parent().remove();//删除属性
    $("#delcfmModel").modal("hide");//模态框隐藏
}
//点击删除按钮时弹出模态框
function deleteProperty1(){
    $("#delcfmModel1").modal("show");
    deleteBtnID=$(event.target).attr("id");
}

function deleteAddRelation(){
    $("#delcfmModel").modal("show");
    deleteBtnID=$(event.target).attr("id");
}
//点击删除按钮时弹出模态框
function deleteRelation(){
    $("#delcfmModel2").modal("show");
    deleteBtnID=$(event.target).attr("id");
}
function deleteRelation1(){
    var relationName=deleteBtnID.substring(0,5);
    console.log(relationName);
    var relationId="";
    if(relationName=="relId"){  //判断是否为已经存在的关联属性
         relationId=deleteBtnID.substring(5);//获取属性id
         console.log(relationId);//
        $.get("/power/relationship/delete/"+relationId); //删除

    }
    $("#"+deleteBtnID).parent().parent().remove();//删除属性
    $("#delcfmModel2").modal("hide");//模态框隐藏
}
//通过属性ID删除
function deletePropertyById() {
    var propertyId=parseInt(deleteBtnID);
    $.get("/power/property/delete/"+propertyId);
    // $("#property"+id).parent().parent().remove();
    $("#"+deleteBtnID).parent().parent().remove();
    $("#delcfmModel1").modal("hide");
}


function deleteDevice() {
    $("#delcfmModel1").modal("show");
    deleteBtnID=$(event.target).attr("id");
    console.log(deleteBtnID);

}
function deleteDeviceById(){
    $.ajax({
        type: "GET",
        url: "/power/device/delete/" + deleteBtnID,
        success: function () {
            $("#delcfmModel1").modal("hide");
            location.reload();
        }
    })
    // $.get("/power/device/delete/"+deleteBtnID);
    // $("#delcfmModel1").modal("hide");
    // location.reload();
}
function toDevice(){
    window.history.back(-1);
}
function toElePrice(){
    window.history.back(-1);
}

function getEnergyStrategy(){
    $("#strategy").modal("show");
}



